﻿

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;


namespace Lib.CommonForm
{
    public class tbl_Roles_Length
    {
        public static int RoleName = 256;
    }

    public class tbl_Roles_Controller
    {
        #region "Contructor"

        private static tbl_Roles_Controller _instance;

        protected tbl_Roles_Controller() { }

        protected void Dispose()
        {
            _instance = null;
        }

        private static object _syncLock = new object();

        public static tbl_Roles_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new tbl_Roles_Controller();
                }
            }
            return _instance;
        }

        #endregion


        public string[] GetAllRoles()
        {
            string[] value = DataConnect.MainServiceWCF().aspnet_Roles_GetAllRoles();
            return value;
        }

        public DataTable GetAll()
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_GetAll();
        }

        public string[] GetRolesForUser(string UserName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_GetRolesForUser(UserName); ;

        }
        public string[] GetUsersInRoles(string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_GetRolesForUser(roleName);
        }

        public bool IsUserInRole(string userName, string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_IsUserInRole(userName, roleName); ;
        }


        public string CreateRole(string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_CreateRole(roleName); ;
        }

        public bool UpdateRole(string roleID, string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_Update(roleID, roleName);
        }

        public bool DeleteRole(string roleName)
        {
            tbl_RoleRight_Controller.Instance().DeleteByRoleName(roleName);

            return Globals.ToBoolean(DataConnect.MainServiceWCF().aspnet_Roles_DeleteRole(roleName));
        }

        public string AddUserToRole(string userName, string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_AddUserToRole(userName, roleName); ;
        }

        public bool RemoveUserFromRole(string userName, string roleName)
        {

            return Globals.ToBoolean(DataConnect.MainServiceWCF().aspnet_Roles_RemoveUserFromRole(userName, roleName));

        }

        public bool RoleExists(string roleName)
        {
            return DataConnect.MainServiceWCF().aspnet_Roles_RoleExists(roleName); ;
        }
    }
}
